/* eslint-disable no-unused-vars */
/* eslint-disable comma-dangle */

var mudcolor = {

  BLK: 'black',
  RED: 'brown',
  GRN: 'green',
  YEL: 'orange',
  BLU: 'steelblue',
  MAG: 'purple',
  CYN: 'darkturquoise',
  WHT: 'gray',

  HIR: 'red',
  HIG: 'springgreen',
  HIY: 'DarkOrange',
  HIB: 'blue',
  HIM: 'magenta',
  HIC: 'cyan',
  HIW: 'white',

  NOR: 'green'
}

function mudcolortext (txtsor) {
  var listspan = []
  listspan = txtsor.split('#')
  var listresult = []
  var color = 'green'
  for (let j = 0, len = listspan.length; j < len; j++) {
    if (j % 2 === 0) {
      var text = listspan[j]
      listresult.push({
        color: color,
        text: text
      })
    } else {
      var tempcolor = mudcolor[listspan[j]]
      if (typeof (tempcolor) === 'undefined') {
        color = listspan[j]
      } else {
        color = tempcolor
      }
    }
  }
  return listresult
}

function genderself (sex) {
  return '你'
}

function genderpronoun (sex) {
  switch (sex) {
    case '男性':
      return '他'
    case '女性':
      return '她'
    default:
      break
  }
  return '它'
}

var ListChDigit = ['零', '十', '百', '千', '万', '亿', '兆']
var ListChNum = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九', '十']
var ListChTien = ['甲', '乙', '丙', '丁', '戊', '己', '庚', '辛', '壬', '癸']
var ListChDee = ['子', '丑', '寅', '卯', '辰', '巳', '午', '未', '申', '酉', '戌', '亥']

function chinesenumber (i) {
  if (i < 0) return '负' + chinesenumber(-i)
  if (i < 11) return ListChNum[i]
  if (i < 20) return ListChNum[10] + ListChNum[i - 10]
  if (i < 100) {
    if (i % 10 === 0) return ListChNum[i / 10] + ListChDigit[1]
    else return ListChNum[i / 10] + ListChDigit[1] + ListChNum[i % 10]
  }
  if (i < 1000) {
    if (i % 100 === 0) {
      return ListChNum[i / 100] + ListChDigit[2]
    } else if (i % 100 < 10) {
      return ListChNum[i / 100] + ListChDigit[2] + ListChNum[0] + chinesenumber(i % 100)
    } else if (i % 100 < 20) {
      return ListChNum[i / 100] + ListChDigit[2] + ListChNum[1] + chinesenumber(i % 100)
    } else {
      return ListChNum[i / 100] + ListChDigit[2] + chinesenumber(i % 100)
    }
  }
  if (i < 10000) {
    if (i % 1000 === 0) {
      return ListChNum[i / 1000] + ListChDigit[3]
    } else if (i % 1000 < 100) {
      return ListChNum[i / 1000] + ListChDigit[3] + ListChDigit[0] + chinesenumber(i % 1000)
    } else {
      return ListChNum[i / 1000] + ListChDigit[3] + chinesenumber(i % 1000)
    }
  }
  if (i < 100000000) {
    if (i % 10000 === 0) {
      return chinesenumber(i / 10000) + ListChDigit[4]
    } else if (i % 10000 < 1000) {
      return chinesenumber(i / 10000) + ListChDigit[4] + ListChDigit[0] + chinesenumber(i % 10000)
    } else {
      return chinesenumber(i / 10000) + ListChDigit[4] + chinesenumber(i % 10000)
    }
  }
  if (i < 1000000000000) {
    if (i % 100000000 === 0) {
      return chinesenumber(i / 100000000) + ListChDigit[5]
    } else if (i % 100000000 < 10000000) {
      return chinesenumber(i / 100000000) + ListChDigit[5] + ListChDigit[0] + chinesenumber(i % 100000000)
    } else {
      return chinesenumber(i / 100000000) + ListChDigit[5] + chinesenumber(i % 100000000)
    }
  }
  if (i % 1000000000000 === 0) {
    return chinesenumber(i / 1000000000000) + ListChDigit[6]
  } else if (i % 1000000000000 < 100000000000) {
    return chinesenumber(i / 1000000000000) + ListChDigit[6] + ListChDigit[0] + chinesenumber(i % 1000000000000)
  } else {
    return chinesenumber(i / 1000000000000) + ListChDigit[6] + chinesenumber(i % 1000000000000)
  }
}

var BvalueSilver = 100
var BvalueGold = 10000

function chinesemoney (i) {
  var sb = ''
  var sum = Math.Max(i, 0)
  var gamount = sum / BvalueGold
  var samount = (sum - (gamount * BvalueGold)) / BvalueSilver
  var camount = sum % BvalueSilver
  if (gamount >= 1) {
    sb += chinesenumber(gamount) + '两#HIY#黄金'
  }
  if (samount >= 1) {
    sb += chinesenumber(samount) + '两#WHT#白银'
  }
  sb += chinesenumber(camount) + '文#YEL#铜板'
  return sb
}

var listdamagedesc = [
  '#HIB#极轻#NOR#',
  '#HIY#很轻#NOR#',
  '#HIM#不重#NOR#',
  '#HIC#很重#NOR#',
  '#HIR#极重#NOR#',
]

function getdemagedesc (damage) {
  var idx = Math.floor(damage / 25)
  if (idx < 0) { idx = 0 } if (idx >= listdamagedesc.length) { idx = listdamagedesc.length - 1 }
  return listdamagedesc[idx]
}

export default {

  mudcolortext: mudcolortext,

  genderself: genderself,
  genderpronoun: genderpronoun,

  chinesenumber: chinesenumber,
  chinesemoney: chinesemoney,

  getdemagedesc: getdemagedesc,

  mudcolor: mudcolor

}
